// add element
let map = new Map();
console.log(map);
map.set({}, 1).set(function () { }, 2).set([], 3);
console.log(map);

// create from array
map = new Map([['x', 10], ['y', 20], ['z', 30]]);
console.log(map);
console.log(map.get('z'), map.get('a'));

// ignore redundant array elements
map = new Map([['x', 10, 'a'], ['y', 20, 'b', 'c'], ['z', 30, 40, 'a']]);
console.log(map);
console.log(map.has('x'), map.size);
console.log(map.delete('x'), map.delete('a'));
console.log(map.has('x'), map.size);
console.log(map.clear(), map, map.size);

// iteration
console.log(map.values(), map.keys(), map.entries());
map = new Map([['a', 1], [1, 2]]);
map.forEach((value, key) => { console.log(key, value, typeof key); });
for (let [key, value] of map) {
    console.log(key, value);
}

// convert to array
let m = new Map([['a', 1], ['b', 2]]);
let arr = Array.from(m);
console.log(arr);

// clone
let origin = new Map([['array', []], ['object', {}]]);
let clone = new Map(origin);
console.log(origin === clone);
console.log(origin.get('array') === clone.get('array'));
console.log(origin.get('object') === clone.get('object'));

// merge
let map1 = new Map([['a', 1], ['b', 2]]);
let map2 = new Map([['a', -1], ['c', 3]]);
let mergedMap = new Map([...map1, ...map2]);
console.log(mergedMap);
